package apptoko.com.view;



import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.TextView;

import apptoko.com.R;


public class CustomDialog extends Dialog {

	private FrameLayout mContentFrame;

	private Button btnLeft;

	private Button btnRight;

	private Context mContext;
	private TextView titleDialog;
	public CustomDialog(Context context, int theme) {
		super(context, R.style.Dialog);
		init(context);
	}

	public CustomDialog(Context context) {
		super(context, R.style.Dialog);
		init(context);
	}

	private void init(Context context) {
		this.mContext = context;
		this.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
		this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.custom_dialog);
		btnLeft = (Button) findViewById(R.id.btnLeft);
		btnRight = (Button) findViewById(R.id.btnRight);
		mContentFrame = (FrameLayout) findViewById(R.id.content_layout);
		titleDialog=(TextView)findViewById(R.id.titleDialog);
		titleDialog.setTextColor(Color.BLUE);
	}
	public void setCustomTitle(String title){
		titleDialog.setVisibility(View.VISIBLE);
		titleDialog.setText(title);
	}
	public void disableCustomTitle(){
		titleDialog.setVisibility(View.GONE);
	}
	public CustomDialog setContentViewDialog(View view) {
		mContentFrame.addView(view, new FrameLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		return this;
	}

	public CustomDialog setContentLayout(int resId) {
		View content_layout = LayoutInflater.from(mContext)
				.inflate(resId, null);
		mContentFrame.addView(content_layout, new FrameLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		return this;
	}

	public CustomDialog setLeftButton(String label,
			View.OnClickListener listener) {
		btnLeft.setText(label);
		btnLeft.setOnClickListener(listener);
		return this;
	}

	public CustomDialog setRightButton(String label,
			View.OnClickListener listener) {
		btnRight.setText(label);
		btnRight.setOnClickListener(listener);
		return this;
	}

}
